package com.fyakm.daodejing;

import com.fyakm.daodejing.simple.EvolutionController;
import com.fyakm.daodejing.simple.Nature;
import com.fyakm.daodejing.simple.Species;
import com.fyakm.daodejing.simple.SpeciesPool;

import java.util.Arrays;
import java.util.List;

public class TestMain {


        public static void main(String[] args) {
            Nature nature = new Nature();

            int[] initialGenes1 = {1, 2, 3, 4, 5};
            Species initialSpecies1 = new Species(initialGenes1);
            SpeciesPool.addSpecies(initialSpecies1);

            int[] initialGenes2 = {6, 7, 8, 9, 10};
            Species initialSpecies2 = new Species(initialGenes2);
            SpeciesPool.addSpecies(initialSpecies2);


            nature.initializeSpecies(initialSpecies1);
            nature.initializeSpecies(initialSpecies2);

            EvolutionController evolutionController = new EvolutionController(0.8, 0.05);

            for (int i = 0; i < 100; i++) {
                nature.evolve(evolutionController);
                System.out.println("第" + i + "轮进化后：");
                // 可以在这里输出每一轮进化后物种池里物种的相关情况，观察进化结果
                nature.getSpeciesList().forEach(species -> {
                    int[] genes = species.getGenes();
                    // 输出genes数组
                    System.out.println(Arrays.toString(genes));
                });
            }
            List<Species> speciesList = nature.getSpeciesList();
            speciesList.forEach(species -> System.out.println(Arrays.stream(species.getGenes()).toArray()));
        }
    }